﻿Imports Microsoft.DirectX
Imports Microsoft.DirectX.Direct3D
Public Class LandschaftstexturWald
    Inherits ObjektLandschaftsTextur

    Dim TexturLandschaftUntergrund As Texture
    Dim TexturBaum As Texture
    Dim Mesh As Objekt3D

    Public Sub New()
        ID = "WALD"
        Landschaftsname = "Wald"
        Deckung = 2
        Tarnung = True
        KP = -1
        TexturenLaden(New String() {"Wald", "Wald+1"})
        Normal = 1
        Ausrichtungslandschaften = New String() {}

        If My.Settings.draw3D Then
            Ini3D()
        End If
    End Sub



    Public Overrides Sub Malen3D(ByVal p_MatCube As Microsoft.DirectX.Matrix, ByVal Landschaft As ObjektLandschaft)
        Grafikengine.Grafikkarte.SetTexture(0, TexturLandschaftUntergrund)
        Dim standardMatrix As Matrix = Grafikengine.Grafikkarte.Transform.World
        Grafikengine.Grafikkarte.Transform.World = p_MatCube

        'Berechnen:
        Dim Farbe As Color = ObjektmarkiertesFeld.getFeldFarbe(Landschaft.KooX, Landschaft.KooY)
        Dim cube(3) As CustomVertex.PositionColoredTextured
        cube(0) = New CustomVertex.PositionColoredTextured(0, 0, 0, Farbe.ToArgb, 0, 1)
        cube(1) = New CustomVertex.PositionColoredTextured(0, 0, 1, Farbe.ToArgb, 0, 0)
        cube(2) = New CustomVertex.PositionColoredTextured(1, 0, 0, Farbe.ToArgb, 1, 1)
        cube(3) = New CustomVertex.PositionColoredTextured(1, 0, 1, Farbe.ToArgb, 1, 0)

        'Anzeigen:
        Grafikengine.Grafikkarte.VertexFormat = CustomVertex.PositionColoredTextured.Format
        Dim M As New Material
        M.Emissive = Farbe
        Grafikengine.Grafikkarte.Material = M
        Grafikengine.Grafikkarte.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, cube)

        ''Berechnen:
        'Dim Baum(3) As CustomVertex.PositionColoredTextured
        'Baum(0) = New CustomVertex.PositionColoredTextured(0, 1.279296875, 0.5, Color.FromArgb(0, 255, 255, 255).ToArgb, 0, 0)
        'Baum(1) = New CustomVertex.PositionColoredTextured(1, 1.279296875, 0.5, Color.FromArgb(0, 255, 255, 255).ToArgb, 1, 0)
        'Baum(2) = New CustomVertex.PositionColoredTextured(0, 0, 0.5, Color.FromArgb(0, 255, 255, 255).ToArgb, 0, 1)
        'Baum(3) = New CustomVertex.PositionColoredTextured(1, 0, 0.5, Color.FromArgb(0, 255, 255, 255).ToArgb, 1, 1)
        ''Anzeigen:
        'Grafikengine.Grafikkarte.SetTexture(0, TexturBaum)
        'Grafikengine.Grafikkarte.VertexFormat = CustomVertex.PositionColoredTextured.Format
        'Grafikengine.Grafikkarte.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, Baum)
        'Baum(2) = Baum(1)
        'Baum(1) = New CustomVertex.PositionColoredTextured(0, 0, 0.5, Color.FromArgb(0, 0, 0, 0).ToArgb, 0, 1)
        'Grafikengine.Grafikkarte.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, Baum)
        Dim X As Single = p_MatCube.M41
        Dim Y As Single = p_MatCube.M43
        p_MatCube.M41 = X + 0.109
        p_MatCube.M43 = Y + 0.32
        'Grafikengine.Grafikkarte.Transform.World = p_MatCube
        Mesh.Malen(p_MatCube)

        p_MatCube.M41 = X + 0.616
        p_MatCube.M43 = Y + 0.03
        'Grafikengine.Grafikkarte.Transform.World = p_MatCube
        Mesh.Malen(p_MatCube)

        p_MatCube.M41 = X + 0.33
        p_MatCube.M43 = Y + 0.707
        'Grafikengine.Grafikkarte.Transform.World = p_MatCube
        Mesh.Malen(p_MatCube)

        p_MatCube.M41 = X + 0.82
        p_MatCube.M43 = Y + 0.33
        'Grafikengine.Grafikkarte.Transform.World = p_MatCube
        Mesh.Malen(p_MatCube)

        p_MatCube.M41 = X + 0.808
        p_MatCube.M43 = Y + 0.84
        'Grafikengine.Grafikkarte.Transform.World = p_MatCube
        Mesh.Malen(p_MatCube)

        'Wieder den Ursprungsstatus wiederherstellen..
        Grafikengine.Grafikkarte.Transform.World = standardMatrix
    End Sub

    Public Overrides Sub Ini3D()
        TexturLandschaftUntergrund = Grafikengine.LoadTexture(My.Settings.Resourcenpfad + "Landschaften\Bilder\3D\" + My.Settings.TexturQuali + "\Waldboden.bmp")
        '  TexturBaum = Grafikengine.LoadTexture(My.Settings.Resourcenpfad + "Landschaften\Bilder\3D\" + My.Settings.TexturQuali + "\Baum.png")
        Mesh = New Objekt3D
        Mesh.MeshBildLaden(My.Settings.Resourcenpfad + "Landschaften\Meshes\Baum.X")
    End Sub

    Public Overrides Sub Tick()

    End Sub
End Class
